<template>
	<view>
		<view class="qiun-columns">
			<view class="qiun-bg-white qiun-title-bar qiun-common-mt">
				<view class="qiun-title-dot-light">大数据与智能工程学院</view>
			</view>
			<view class="qiun-charts">
				<canvas canvas-id="canvasRing" id="canvasRing" class="charts" @touchstart="touchRing"></canvas>
			</view>
		</view>


		<view class="qiun-columns">
			<view class="qiun-bg-white qiun-title-bar qiun-common-mt">
				<view class="qiun-title-dot-light">教师使用率</view>
			</view>
			<view class="qiun-charts">
				<canvas canvas-id="canvasPie" id="canvasPie" class="charts" @touchstart="touchPie"></canvas>
			</view>
		</view>
	</view>

</template>

<script>
	import uCharts from '@/lib/u-charts/u-charts.js';
	var _self;
	var canvaRing = null;
	var canvaPie=null;

	export default {
		data() {
			return {
				cWidth: '',
				cHeight: '',
				pixelRatio: 1,
				serverData: '',
			}
		},
		onLoad() {
			_self = this;
			this.cWidth = uni.upx2px(750);
			this.cHeight = uni.upx2px(500);
			this.getServerData();
		},
		methods: {
			getServerData() {
				let Ring = {
					series: [{
						"name": "对口高职",
						"data": 50
					}, {
						"name": "软件工程",
						"data": 30
					}, {
						"name": "物联网工程",
						"data": 20
					}, {
						"name": "大数据与云计算",
						"data": 18
					}, {
						"name": "网络工程",
						"data": 8
					}]
				};
				
				let Pie = {
					series: [{
						"name": "对口高职",
						"data": 50
					}, {
						"name": "软件工程",
						"data": 30
					}, {
						"name": "物联网工程",
						"data": 20
					}, {
						"name": "大数据与云计算",
						"data": 18
					}, {
						"name": "网络工程",
						"data": 8
					}]
				}
				
				//这里我后台返回的是数组，所以用等于，如果您后台返回的是单条数据，需要push进去
				// Ring.series=res.data.data.Ring.series;
				_self.showRing("canvasRing", Ring);
				_self.showPie("canvasPie",Pie);
			},
			showRing(canvasId, chartData) {
				canvaRing = new uCharts({
					$this: _self,
					canvasId: canvasId,
					type: 'ring',
					fontSize: 11,
					legend: true,
					extra: {
						pie: {
							offsetAngle: -45,
							ringWidth: 40 * _self.pixelRatio,
							labelWidth: 15
						}
					},
					title: {
							name: '70%',
							color: '#7cb5ec',
							fontSize: 25,
							offsetY:-20,
						},
						subtitle: {
							name: '签到率',
							color: '#666666',
							fontSize: 15,
							offsetY:30,
						},
					background: '#FFFFFF',
					pixelRatio: _self.pixelRatio,
					series: chartData.series,
					animation: true,
					width: _self.cWidth * _self.pixelRatio,
					height: _self.cHeight * _self.pixelRatio,
					disablePieStroke: true,
					dataLabel: true,
				});
			},

			//教师使用率
			showPie(canvasId, chartData) {
				canvaPie = new uCharts({
					$this: _self,
					canvasId: canvasId,
					type: 'rose',
					fontSize: 11,
					legend: {
						show: true
					},
					background: '#FFFFFF',
					pixelRatio: _self.pixelRatio,
					series: chartData.series,
					animation: true,
					width: _self.cWidth * _self.pixelRatio,
					height: _self.cHeight * _self.pixelRatio,
					dataLabel: true,
					extra: {
						rose: {
							type: 'area',
							minRadius: 50,
							activeOpacity: 0.5,
							offsetAngle: 0,
							labelWidth: 15
						}
					},
				});
			},

			touchRing(e) {
				canvaRing.showToolTip(e, {
					format: function(item) {
						return item.name + ':' + item.data
					}
				});
			},

			touchPie(e) {
				canvaPie.showToolTip(e, {
					format: function(item) {
						return item.name + ':' + item.data
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #F2F2F2;
		width: 750upx;
		overflow-x: hidden;
	}

	.qiun-padding {
		padding: 2%;
		width: 96%;
	}

	.qiun-wrap {
		display: flex;
		flex-wrap: wrap;
	}

	.qiun-rows {
		display: flex;
		flex-direction: row !important;
	}

	.qiun-columns {
		display: flex;
		flex-direction: column !important;
	}

	.qiun-common-mt {
		margin-top: 10upx;
	}

	.qiun-bg-white {
		background: #FFFFFF;
	}

	.qiun-title-bar {
		width: 96%;
		padding: 10upx 2%;
		flex-wrap: nowrap;
	}

	.qiun-title-dot-light {
		border-left: 10upx solid #0ea391;
		padding-left: 10upx;
		font-size: 32upx;
		color: #000000
	}

	.qiun-charts {
		width: 750upx;
		height: 500upx;
		background-color: #FFFFFF;
	}

	.charts {
		width: 750upx;
		height: 500upx;
		background-color: #FFFFFF;
	}
</style>
